package com.cdd.servicebankcard.config;

import com.alibaba.druid.pool.DruidDataSource;

import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @Description TODO
 * @Author: cdd
 * @Date: 2020/7/30 16:33
 * @Version: 1.0
 */
@Configuration
public class DataSourceConfig {

    private final ApplicationContext applicationContext;

    public DataSourceConfig(ApplicationContext applicationContext){
        this.applicationContext = applicationContext;
    }

    @Bean
    @ConfigurationProperties(prefix = "spring.datasource.ds0")
    public DruidDataSource ds0(){
        DruidDataSource druidDataSource = new DruidDataSource();
        return druidDataSource;
    }

    @Primary
    @Bean
    public DataSource dataSource(DruidDataSource ds0){
        DataSourceProxy pds0 = new DataSourceProxy(ds0);
        return pds0;
    }
}
